<?php
class WbPageLinkController extends  DomController {

	
	public function page( $id ) {

		$item = DomAr::load( $id, 'WbPage');
		$post = DomFgPost::getInstance();

		$this->loadController('Wb')->_updatePage( $item );
		
		if( $post->save ) {
			
			$item->link = $post->link;
			
			if( $item->save() ) {
				$id = $item->id;
				$message = array('type' => 'ok','colspan' => 2,'message' => 'Salvestatud',);
			} else {
				$message = array('message' => 'Tekkinud on viga!','type' => 'ok','colspan' => 2,'description' => implode('<br>',$item->getValidationReport()->messages),);
			}
		}
		
		
		$tabPanel = array(
			'type' => 'tabPanel',
			'action' => $this->getUrl('site/'.$id),
			'headerTabs' => true,
			'border' => true,
			'frame' => true,
			'action' => $this->getUrl('page/'.$id.'/'.$parentId),
			'items' => array($message),
			'buttons' => array(
				array(
					'title' => 'Salvesta',
					'name' => 'save'
				),
			),
		);
		
		// -------------------------------------------
			
		$overallTab = array(
			'title' => 'Üldine',
			'layout' => 'table',
			'layoutConfig' => array(
				'columns' => 2,
				'columnWidths' => array( 150 ),
			),
			'items' => array(
				$this->loadController('Wb')->_getPageItems( $item ),
				array(
					'type' => 'textField',
					'name' => 'link',
					'title' => 'Link',
					'value' => $item->link,
				),
			),
		);
		$tabPanel['items'][] = &$overallTab;
		
		// -------------------------------------------
		
		$tabPanel['items'][] = $this->loadController('Wb')->_getPagePanels( $item );
		
		$this->view->contents = DomFg::render( $tabPanel );
		
		$this->loadController('Wb')->_renderSiteTree( $item->getRoot(), $item );
		
	}


}